/*
 * Copyright 2022-2029 heshuixing(https://gitee.com/heshuixing)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mercury.ec.framework.air.core.client.impl.sunstn;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.mercury.ec.framework.air.core.client.dto.order.cancel.AirOrderCancelReqDTO;
import com.mercury.ec.framework.air.core.client.dto.order.cancel.AirOrderCancelRespDTO;
import com.mercury.ec.framework.air.core.client.dto.order.create.AirOrderCreateReqDTO;
import com.mercury.ec.framework.air.core.client.dto.order.create.AirOrderCreateRespDTO;
import com.mercury.ec.framework.air.core.client.dto.order.issue.AirOrderIssuePassengerRespDTO;
import com.mercury.ec.framework.air.core.client.dto.order.issue.AirOrderIssueReqDTO;
import com.mercury.ec.framework.air.core.client.dto.order.issue.AirOrderIssueRespDTO;
import com.mercury.ec.framework.air.core.client.dto.order.issue.AirOrderIssueRouteRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.detr.AirDetrReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.detr.AirDetrRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.flight.AirSearchFlightReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.flight.AirSearchFlightRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.pat.AirPatReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.pat.AirPatRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.patex.AirPatexReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.patex.AirPatexRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.price.AirSearchPriceReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.price.AirSearchPriceRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.raw.AirRawReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.raw.AirRawRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtPassengerRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtRouteRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rtkt.AirRtktReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rtkt.AirRtktRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.xsfsi.AirXsfsiReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.xsfsi.AirXsfsiRespDTO;
import com.mercury.ec.framework.air.core.client.impl.AbstractAirClient;
import com.mercury.ec.framework.air.core.client.impl.sunstn.convert.SunstnConvert;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.SunstnCommonRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.detr.SunstnDetrReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.detr.SunstnDetrRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.etdz.SunstnEtdzReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.etdz.SunstnEtdzRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.pat.SunstnPatReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.pat.SunstnPatRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.patex.SunstnPatexReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.patex.SunstnPatexRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.raw.SunstnRawReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.raw.SunstnRawRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.rt.SunstnRtReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.rt.SunstnRtRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.rtkt.SunstnRtktReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.rtkt.SunstnRtktRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.sd.SunstnSdReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.sd.SunstnSdRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.sd.SunstnSdRetRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.xepnr.SunstnXepnrReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.xepnr.SunstnXepnrRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.xsfsi.SunstnXsfsiReqDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.dto.xsfsi.SunstnXsfsiRespDTO;
import com.mercury.ec.framework.air.core.client.impl.sunstn.execute.DefaultSunstnAirExecute;
import com.mercury.ec.framework.air.core.client.impl.sunstn.execute.SunstnAirExecute;
import com.mercury.ec.framework.air.core.client.validator.AirClientGroup;
import com.mercury.ec.framework.air.core.property.AirChannelProperties;
import com.mercury.ec.framework.common.enums.CardTypeEnum;
import com.mercury.ec.framework.common.enums.CommonStatusEnum;
import com.mercury.ec.framework.common.util.validation.ValidationUtils;
import com.mercury.ec.module.air.validator.AirGroup;
import com.mercury.ec.module.basic.dal.dataobject.office.OfficeDO;
import com.mercury.ec.module.basic.service.office.OfficeService;
import lombok.extern.slf4j.Slf4j;

import javax.validation.Valid;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static com.mercury.ec.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.mercury.ec.module.air.enums.ErrorCodeConstants.AIR_SUNSTN_API_CALL_EXCEPTION;
import static com.mercury.ec.module.air.enums.ErrorCodeConstants.AIR_SUNSTN_API_OFFICE_NOT_NULL;

/**
 * 新港机票客户端
 *
 * @author hesx
 */
@Slf4j
public class SunstnAirClient extends AbstractAirClient {

    private SunstnAirExecute sunstnAirExecute;
    private OfficeService officeService;

    public SunstnAirClient(AirChannelProperties properties) {
        super(properties);
    }

    @Override
    protected void doInit() {
        sunstnAirExecute = new DefaultSunstnAirExecute();
        officeService = SpringUtil.getBean(OfficeService.class);
    }

    private OfficeDO getOffice(String officeNo) {
        OfficeDO officeDO;
        if (StrUtil.isNotBlank(officeNo)) {
            officeDO = officeService.getOfficeByOfficeNo(officeNo);
        } else {
            officeDO = officeService.getDefaultOffice();
        }
        if (officeDO == null) {
            throw exception(AIR_SUNSTN_API_OFFICE_NOT_NULL, "未维护相关 OFFICE 信息，请联系管理员");
        }
        if (CommonStatusEnum.DISABLE.getStatus().equals(officeDO.getStatus())) {
            throw exception(AIR_SUNSTN_API_OFFICE_NOT_NULL, "OFFICE 已停用，请联系管理员");
        }
        return officeDO;
    }

    @Override
    public AirSearchFlightRespDTO getFlight(AirSearchFlightReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirSearchPriceRespDTO getPrice(AirSearchPriceReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirRtRespDTO rt(@Valid AirRtReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnRtReqDTO sunstnRtReqDTO = SunstnConvert.getSunstnRtReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnRtRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnRtReqDTO, SunstnRtRespDTO.class);
        // 解析响应
        SunstnRtRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnRtReqDTO.getCmd(), data.getErr_info());
        }
        return SunstnConvert.getAirRtRespDTO(sunstnRtReqDTO, data);
    }

    @Override
    public List<AirPatRespDTO> pat(@Valid AirPatReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnPatReqDTO sunstnPatReqDTO = SunstnConvert.getSunstnPatReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnPatRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnPatReqDTO, SunstnPatRespDTO.class);
        // 解析响应
        SunstnPatRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getErr_info())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnPatReqDTO.getCmd(), XmlUtil.parseXml(sunstnCommonRespDTO.getXml()).getDocumentElement().getTextContent());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnPatReqDTO.getCmd(), data.getErr_info());
        }
        return SunstnConvert.getAirPatRespDTO(reqDTO, data);
    }

    @Override
    public List<AirPatexRespDTO> patex(@Valid AirPatexReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnPatexReqDTO sunstnPatexReqDTO = SunstnConvert.getSunstnPatexReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnPatexRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnPatexReqDTO, SunstnPatexRespDTO.class);
        // 解析响应
        SunstnPatexRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getErr_info())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnPatexReqDTO.getCmd(), sunstnCommonRespDTO.getXml());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnPatexReqDTO.getCmd(), data.getErr_info());
        }
        return SunstnConvert.getAirPatexRespDTO(reqDTO, data);
    }

    @Override
    public List<AirXsfsiRespDTO> xsfsi(@Valid AirXsfsiReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnXsfsiReqDTO sunstnXsfsiReqDTO = SunstnConvert.getSunstnXsfsiReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnXsfsiRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnXsfsiReqDTO, SunstnXsfsiRespDTO.class);
        // 解析响应
        SunstnXsfsiRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getErr_info())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnXsfsiReqDTO.getCmd(), sunstnCommonRespDTO.getXml());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnXsfsiReqDTO.getCmd(), data.getErr_info());
        }
        return SunstnConvert.getAirXsfsiRespDTO(reqDTO, data);
    }

    @Override
    public AirDetrRespDTO detr(@Valid AirDetrReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnDetrReqDTO sunstnDetrReqDTO = SunstnConvert.getSunstnDetrReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnDetrRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnDetrReqDTO, SunstnDetrRespDTO.class);
        // 解析响应
        SunstnDetrRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getErr_info())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnDetrReqDTO.getCmd(), XmlUtil.parseXml(sunstnCommonRespDTO.getXml()).getDocumentElement().getTextContent());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnDetrReqDTO.getCmd(), data.getErr_info());
        }
        return SunstnConvert.getAirDetrRespDTO(data);
    }

    @Override
    public AirRawRespDTO raw(@Valid AirRawReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnRawReqDTO sunstnRawReqDTO = new SunstnRawReqDTO(HexUtil.encodeHexStr(reqDTO.getCmd(), Charset.forName("GB18030"))); // 指令必需16进制编码
        SunstnCommonRespDTO<SunstnRawRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnRawReqDTO, SunstnRawRespDTO.class);
        SunstnRawRespDTO data = sunstnCommonRespDTO.getData();
        AirRawRespDTO airRawRespDTO = new AirRawRespDTO();
        airRawRespDTO.setContent(data.getContent());
        return airRawRespDTO;
    }

    @Override
    public AirRtktRespDTO rtkt(@Valid AirRtktReqDTO reqDTO) {
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnRtktReqDTO sunstnRtktReqDTO = SunstnConvert.getSunstnRtktReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnRtktRespDTO> sunstnCommonRespDTO = new DefaultSunstnAirExecute().execute(office.getUrl(), office.getApiAccount(), sunstnRtktReqDTO, SunstnRtktRespDTO.class);
        SunstnRtktRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getErr_info())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnRtktReqDTO.getCmd(), XmlUtil.parseXml(sunstnCommonRespDTO.getXml()).getDocumentElement().getTextContent());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnRtktReqDTO.getCmd(), data.getErr_info());
        }
        return SunstnConvert.getAirRtktRespDTO(data);
    }

    @Override
    public AirOrderCreateRespDTO createOrder(AirOrderCreateReqDTO reqDTO) {
        // 校验
        ValidationUtils.validate(reqDTO, AirClientGroup.Sunstn.class);
        reqDTO.getRoutes().forEach(p -> ValidationUtils.validate(p, AirClientGroup.Sunstn.class));
        reqDTO.getPassengers().stream().filter(p -> !CardTypeEnum.isIdCard(p.getCardType())).forEach(p -> ValidationUtils.validate(p, AirGroup.NotIdCard.class));
        OfficeDO office = getOffice(reqDTO.getBookOffice());
        SunstnSdReqDTO sunstnSdReqDTO = SunstnConvert.getSunstnSdReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnSdRespDTO> sunstnCommonRespDTO = sunstnAirExecute.execute(office.getUrl(), office.getApiAccount(), sunstnSdReqDTO, SunstnSdRespDTO.class);
        // 解析响应
        SunstnSdRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getResult() || CollUtil.isEmpty(data.getRets())) {
//            if (StrUtil.isBlank(data.getErr_info())) {
//                // 兼容非属性方式返回异常信息
//                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnSdReqDTO.getCmd(), sunstnCommonRespDTO.getXml());
//            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnSdReqDTO.getCmd(), sunstnCommonRespDTO.getXml());
        }
        List<SunstnSdRetRespDTO> rets = data.getRets();
        for (SunstnSdRetRespDTO ret : rets) {
            if (!ret.getResult() || StrUtil.isBlank(ret.getPnr())) {
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnSdReqDTO.getCmd(), ret.getErrinfo());
            }
        }
        return SunstnConvert.getAirOrderCreateRespDTO(data);
    }

    @Override
    public AirOrderCancelRespDTO cancelOrder(AirOrderCancelReqDTO reqDTO) {
        // 校验
        ValidationUtils.validate(reqDTO, AirClientGroup.Sunstn.class);
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnXepnrReqDTO sunstnXepnrReqDTO = SunstnConvert.getSunstnXepnrReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnXepnrRespDTO> sunstnCommonRespDTO = sunstnAirExecute.execute(office.getUrl(), office.getApiAccount(), sunstnXepnrReqDTO, SunstnXepnrRespDTO.class);
        // 解析响应
        SunstnXepnrRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getContent())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnXepnrReqDTO.getCmd(), sunstnCommonRespDTO.getXml());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnXepnrReqDTO.getCmd(), data.getContent());
        }
        return SunstnConvert.getAirOrderCancelRespDTO(data);
    }

    @Override
    public AirOrderIssueRespDTO issueOrder(AirOrderIssueReqDTO reqDTO) {
        // 校验
        ValidationUtils.validate(reqDTO, AirClientGroup.Sunstn.class);
        OfficeDO office = getOffice(reqDTO.getOfficeNo());
        SunstnEtdzReqDTO sunstnEtdzReqDTO = SunstnConvert.getSunstnEtdzReqDTO(reqDTO);
        SunstnCommonRespDTO<SunstnEtdzRespDTO> sunstnCommonRespDTO = sunstnAirExecute.execute(office.getUrl(), office.getApiAccount(), sunstnEtdzReqDTO, SunstnEtdzRespDTO.class);
        // 解析响应
        SunstnEtdzRespDTO data = sunstnCommonRespDTO.getData();
        if (!data.getRet_value()) {
            if (StrUtil.isBlank(data.getContent())) {
                // 兼容非属性方式返回异常信息
                throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnEtdzReqDTO.getCmd(), sunstnCommonRespDTO.getXml());
            }
            throw exception(AIR_SUNSTN_API_CALL_EXCEPTION, sunstnEtdzReqDTO.getCmd(), data.getContent());
        }
        AirOrderIssueRespDTO airOrderIssueRespDTO = new AirOrderIssueRespDTO();
        airOrderIssueRespDTO.setSuccess(true);
        airOrderIssueRespDTO.setPnr(reqDTO.getPnr());
        try {
            // RT提取
            AirRtReqDTO airRtReqDTO = new AirRtReqDTO();
            airRtReqDTO.setPnr(reqDTO.getPnr());
            airRtReqDTO.setScopeType(reqDTO.getScopeType());
            AirRtRespDTO rtResult = rt(airRtReqDTO);

            // RTKT提取
            AirRtktReqDTO airRtktReqDTO = new AirRtktReqDTO();
            airRtktReqDTO.setOfficeNo(reqDTO.getOfficeNo());
            airRtktReqDTO.setAirlineIssueNo(rtResult.getPassengers().get(0).getAirlineIssueNo());
            airRtktReqDTO.setTicketNo(rtResult.getPassengers().get(0).getTicketNo());
            AirRtktRespDTO rtktResult = rtkt(airRtktReqDTO);

            airOrderIssueRespDTO.setAgencyFee(rtktResult.getAgencyFee());
            airOrderIssueRespDTO.setBookOffice(rtResult.getBookOffice());
            airOrderIssueRespDTO.setIssueOffice(rtResult.getIssueOffice());
            airOrderIssueRespDTO.setPnrStatus(rtResult.getPnrStatus());
            airOrderIssueRespDTO.setBigPnr(rtResult.getBigPnr());
            airOrderIssueRespDTO.setIssueTime(rtResult.getIssueTime() == null ? LocalDateTime.now() : rtResult.getIssueTime());
            airOrderIssueRespDTO.setPnrContent(rtResult.getPnrContent());

            List<AirOrderIssueRouteRespDTO> routes = new ArrayList<>();
            for (AirRtRouteRespDTO route : rtResult.getRoutes()) {
                AirOrderIssueRouteRespDTO airOrderIssueRouteRespDTO = new AirOrderIssueRouteRespDTO();
                airOrderIssueRouteRespDTO.setAirlineNo(route.getAirlineNo());
                airOrderIssueRouteRespDTO.setFlightNo(route.getFlightNo());
                airOrderIssueRouteRespDTO.setCabin(route.getCabin());
                airOrderIssueRouteRespDTO.setDiscount(route.getDiscount());
                airOrderIssueRouteRespDTO.setDepart(route.getDepart());
                airOrderIssueRouteRespDTO.setArrive(route.getArrive());
                airOrderIssueRouteRespDTO.setFlightDate(route.getFlightDate());
                airOrderIssueRouteRespDTO.setDepartTime(route.getDepartTime());
                airOrderIssueRouteRespDTO.setArriveTime(route.getArriveTime());
                airOrderIssueRouteRespDTO.setDepartTerminal(route.getDepartTerminal());
                airOrderIssueRouteRespDTO.setArriveTerminal(route.getArriveTerminal());
                airOrderIssueRouteRespDTO.setRouteStatus(route.getRouteStatus());
                airOrderIssueRouteRespDTO.setBaggageWeight(rtktResult.getBaggageWeight());
                routes.add(airOrderIssueRouteRespDTO);
            }
            airOrderIssueRespDTO.setRoutes(routes);

            List<AirOrderIssuePassengerRespDTO> passengers = new ArrayList<>();
            for (AirRtPassengerRespDTO passenger : rtResult.getPassengers()) {
                AirOrderIssuePassengerRespDTO airOrderIssuePassengerRespDTO = new AirOrderIssuePassengerRespDTO();
                airOrderIssuePassengerRespDTO.setName(passenger.getName());
                airOrderIssuePassengerRespDTO.setType(passenger.getType());
                airOrderIssuePassengerRespDTO.setHaveBaby(passenger.getHaveBaby());
                airOrderIssuePassengerRespDTO.setCountryNo(passenger.getCountryNo());
                airOrderIssuePassengerRespDTO.setCardIssuingCountryNo(passenger.getCardIssuingCountryNo());
                airOrderIssuePassengerRespDTO.setCardType(passenger.getCardType());
                airOrderIssuePassengerRespDTO.setCardNo(passenger.getCardNo());
                airOrderIssuePassengerRespDTO.setCardValidDate(passenger.getCardValidDate());
                airOrderIssuePassengerRespDTO.setSex(passenger.getSex());
                airOrderIssuePassengerRespDTO.setBirthday(passenger.getBirthday());
                airOrderIssuePassengerRespDTO.setAirlineIssueNo(passenger.getAirlineIssueNo());
                airOrderIssuePassengerRespDTO.setTicketNo(passenger.getTicketNo());
                airOrderIssuePassengerRespDTO.setTicketLastNo(passenger.getTicketLastNo());
                airOrderIssuePassengerRespDTO.setMobile(passenger.getMobile());
                passengers.add(airOrderIssuePassengerRespDTO);
            }
            airOrderIssueRespDTO.setPassengers(passengers);
        } catch (Exception e) {
            airOrderIssueRespDTO.setSuccess(false);
            log.error("新港etdz出票，RT/RTKT提取，编码【{}】office号【{}】接口异常", reqDTO.getPnr(), reqDTO.getOfficeNo(), e);
        }
        return airOrderIssueRespDTO;
    }
}
